package logic

import (
	"context"
	"gozeroProject/model"
	"gozeroProject/rpc/internal/svc"
	"gozeroProject/rpc/pb/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserLogic {
	return &AddUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddUserLogic) AddUser(in *user.AddUserReq) (*user.AddUserResp, error) {

	users := model.User{
		UserId:   in.UserId,
		Name:     in.Name,
		Mobile:   in.Mobile,
		Gender:   in.Gender,
		Nickname: in.Nickname,
		Type:     int64(in.Type),
	}
	result := l.svcCtx.DB.Create(&users)
	if result.Error != nil {
		return nil, result.Error
	}
	return &user.AddUserResp{Success: "数据插入成功！"}, nil
}
